import { createRouter,createWebHashHistory} from "vue-router"

const asyncRoutes=[
    {
        path:"/",
        redirect:"/home"
    },
    {
        path:"/home",
        component:()=>import("../views/Home/Home.vue"),
        meta:{
            isShowNav:true
        }
    },
    {
        path:"/category",
        component:()=>import("../views/Category/Category.vue"),
        meta:{
            isShowNav:true
        }
    },
    {
        path:"/cart",
        component:()=>import("../views/Cart/Cart.vue"),
        meta:{
            isShowNav:true
        }
    },
    {
        path:"/user",
        component:()=>import("../views/User/User.vue"),
        meta:{
            isShowNav:true
        }
    },
    {
        path:"/usermgment",
        component:()=>import("../views/User/UserMgment.vue"),
        meta:{
            isShowNav:false
        },
        // beforeEnter: (to, from,next) => {
        //     let mltoken=localStorage.getItem("mltoken")
        //     if(mltoken){
        //         next()
        //     }else{
        //         next("/login")
        //     }
        //   },
    },
    {
        path:"/login",
        component:()=>import("../views/Login/Login.vue"),
        meta:{
            isShowNav:false
        }
    },
    {
        path:"/info/:productid",
        component:()=>import("../views/Info/Info.vue"),
        meta:{
            isShowNav:false
        }
    },
    {
        path:"/addresslist",
        component:()=>import("../views/Address/AddressList.vue"),
        meta:{
            isShowNav:false
        }
    },
    {
        path:"/addressaddedit",
        component:()=>import("../views/Address/AddressAddEdit.vue"),
        meta:{
            isShowNav:false
        }
    },
    {
        path:"/createorder",
        component:()=>import("../views/CreateOrder/CreateOrder.vue"),
        meta:{
            isShowNav:false
        }
    },
    {
        path:"/order",
        component:()=>import("../views/Order/Order.vue"),
        meta:{
            isShowNav:false,
            title:"订单页"
        }
    },
    {
        path:"/orderdetail",
        component:()=>import("../views/Order/OrderDetail.vue"),
        meta:{
            isShowNav:false,
            title:"订单详情"
        }
    },
    {
        path:"/about",
        component:()=>import("../views/About/About.vue"),
        meta:{
            isShowNav:false,
        }
    },
]

const router =createRouter({
    history:createWebHashHistory(),
    routes:[
        ...asyncRoutes,
        {path:"/:pathMatch(.*)",redirect:"/"}
    ]
})
router.beforeEach((to,from,next)=>{
   document.title= to.meta.title || "码路严选"
   next()
})
export default router